<?php

   date_default_timezone_set('Australia/Melbourne');
$dateToday=date("Y-m-d");
$csvsfolder = "./csvs/";
$filename="testuploadcsv.csv";
$filename=$_GET['filename'];


$orgFile = fopen($csvsfolder.$filename,"r");
$counter=0;
$abnormal = 1;
$numberExist = 0;

$abbrivation= array("ACCESS","ACCS","ALLEY","ALLY","ALLEYWAY","ALWY","AMBLE","AMBL","ANCHORAGE","ANCG","APPROACH","APP","ARCADE","ARC","ARTERY","ART","AVENUE","AVE","BASIN","BASN","BEACH","BCH","BEND","BEND","BLOCK","BLK","BOULEVARD","BVD","BRACE","BRCE","BRAE","BRAE","BREAK","BRK","BRIDGE","BDGE","BROADWAY","BDWY","BROW","BROW","BYPASS","BYPA","BYWAY","BYWY","CAUSEWAY","CAUS","CENTRE","CTR","CENTREWAY","CNWY","CHASE","CH","CIRCLE","CIR","CIRCLET","CLT","CIRCUIT","CCT","CIRCUS","CRCS","CLOSE","CL","COLONNADE","CLDE","COMMON","CMMN","CONCOURSE","CON","COPSE","CPS","CORNER","CNR","CORSO","CSO","COURT","CT","COURTYARD","CTYD","COVE","COVE","CRESCENT","CRES","CREST","CRST","CROSS","CRSS","CROSSING","CRSG","CROSSROAD","CRD","CROSSWAY","COWY","CRUISEWAY","CUWY","CUL-DE-SAC","CDS","CUTTING","CTTG","DALE","DALE","DELL","DELL","DEVIATION","DEVN","DIP","DIP","DISTRIBUTOR","DSTR","DRIVE","DR","DRIVEWAY","DRWY","EDGE","EDGE","ELBOW","ELB","END","END","ENTRANCE","ENT","ESPLANADE","ESP","ESTATE","EST","EXPRESSWAY","EXP","EXTENSION","EXTN","FAIRWAY","FAWY","FIRE TRACK","FTRK","FIRETRAIL","FITR","FLAT","FLAT","FOLLOW","FOLW","FOOTWAY","FTWY","FORESHORE","FSHR","FORMATION","FORM","FREEWAY","FWY","FRONT","FRNT","FRONTAGE","FRTG","GAP","GAP","GARDEN","GDN","GARDENS","GDNS","GATE","GTE","GATES","GTES","GLADE","GLD","GLEN","GLEN","GRANGE","GRA","GREEN","GRN","GROUND","GRND","GROVE","GR","GULLY","GLY","HEIGHTS","HTS","HIGHROAD","HRD","HIGHWAY","HWY","HILL","HILL","INTERCHANGE","INTG","INTERSECTION","INTN","JUNCTION","JNC","KEY","KEY","LANDING","LDG","LANE","LANE","LANEWAY","LNWY","LEES","LEES","LINE","LINE","LINK","LINK","LITTLE","LT","LOOKOUT","LKT","LOOP","LOOP","LOWER","LWR","MALL","MALL","MEANDER","MNDR","MEW","MEW","MEWS","MEWS","MOTORWAY","MWY","MOUNT","MT","NOOK","NOOK","OUTLOOK","OTLK","PARADE","PDE","PARK","PARK","PARKLANDS","PKLD","PARKWAY","PKWY","PART","PART","PASS","PASS","PATH","PATH","PATHWAY","PHWY","PIAZZA","PIAZ","PLACE","PL","PLATEAU","PLAT","PLAZA","PLZA","POCKET","PKT","POINT","PNT","PORT","PORT","PROMENADE","PROM","QUAD","QUAD","QUADRANGLE","QDGL","QUADRANT","QDRT","QUAY","QY","QUAYS","QYS","RAMBLE","RMBL","RAMP","RAMP","RANGE","RNGE","REACH","RCH","RESERVE","RES","REST","REST","RETREAT","RTT","RIDE","RIDE","RIDGE","RDGE","RIDGEWAY","RGWY","RIGHT OF WAY","ROWY","RING","RING","RISE","RISE","RIVER","RVR","RIVERWAY","RVWY","RIVIERA","RVRA","ROAD","RD","ROADS","RDS","ROADSIDE","RDSD","ROADWAY","RDWY","RONDE","RNDE","ROSEBOWL","RSBL","ROTARY","RTY","ROUND","RND","ROUTE","RTE","ROW","ROW","RUE","RUE","RUN","RUN","SERVICE WAY","SWY","SIDING","SDNG","SLOPE","SLPE","SOUND","SND","SPUR","SPUR","SQUARE","SQ","STAIRS","STRS","STATE HIGHWAY","SHWY","STEPS","STPS","STRAND","STRA","STREET","ST","STRIP","STRP","SUBWAY","SBWY","TARN","TARN","TERRACE","TCE","THOROUGHFARE","THOR","TOLLWAY","TLWY","TOP","TOP","TOR","TOR","TOWERS","TWRS","TRACK","TRK","TRAIL","TRL","TRAILER","TRLR","TRIANGLE","TRI","TRUNKWAY","TKWY","TURN","TURN","UNDERPASS","UPAS","UPPER","UPR","VALE","VALE","VIADUCT","VDCT","VIEW","VIEW","VILLAS","VLLS","VISTA","VSTA","WADE","WADE","WALK","WALK","WALKWAY","WKWY","WAY","WAY","WHARF","WHRF","WYND","WYND","YARD","YARD","BOX","P.O.BOX","P.O");



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $dateToday; ?> Waiting For Post </title>
</head>

<body style="margin:0;">
<H2>POST SLIPS on <?php echo $dateToday;?> for <?php echo $filename ?>   Sign By :_____________</H2>
<table width="1120" border="1" cellspacing="0" cellpadding="0" style="font-family:Arial; font-size:12px;
border-color:#666; border-style:solid border-width:1px;">
  <tr>  
    <td style="width:180px;">#Order</td>
    <td style="width:70px;">Thumb</td>
    <td style="width:200px;">Title</td>
    <td style="width:30px;">Qty</td>
    <td style="width:200px;">Customer Label</td>
    <td style="width:50px;">Price</td>
    <td style="width:150px;">Address</td>
    <td style="width:50px;">PostType&amp;Fee</td>
    <td style="width:50px;">PACKED</td>
    <td style="width:140px;">Tracking Label</td>
  </tr>
<?php
while(($lineData = fgetcsv($orgFile,0))!= FALSE){
	if($counter>0){
	$numberExist = 0;
	$abnormal = 1;
	
	$addr1Arr = explode(" ",str_replace("/"," ",$lineData[5]));
	$add2Arr = explode(" ",str_replace("/"," ",$lineData[6]));
	
	foreach($addr1Arr as $key =>$value){
			if(is_numeric($value)){
				$numberExist = 1;				
				}
			if(in_array(strtoupper($value),$abbrivation)===true){
				$abnormal = 0;
				}			
				
		}
/*		
	if(strlen(trim($lineData[6]))){	
	foreach($addr2Arr as $key =>$value){
			if(is_numeric($value)){
				$numberExist = 1;
				}	
			if(in_array(strtoupper($value),$abbrivation)===true){
				$abnormal = 0;
				}						
		}}				
*/
?>  
  <tr>  	
    <td style="border:none;">#<?php echo $lineData[0]?>
    <?php
 	$date1 = date_create(date("d-M-y"));
	
	$date2 = date_create(trim($lineData[25]));
	$diff = date_diff($date1,$date2);
    echo $diff->format('%R%a days');
   ?>   
    <br /><img src="http://192.168.1.124/sample/sample-gd.php?sno=<?php echo $lineData[0]?>" / border="0"></td>
    <td><img src="http://thumbs.ebaystatic.com/pict/<?php echo $lineData[12]?>6464_.jpg" border="0" /></td>
    <td><?php echo $lineData[14]?></td>
    <td><?php
    if($lineData[15]>1){
		echo "<b style=\"font-size:16px;\">[".$lineData[15]."]</b>";
		}
	else{
		echo $lineData[15];
		}	
	
	?></td>
    <td valign="top"><?php echo $lineData[31]?><br /><?php echo $lineData[30]?><br />
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _</td>
    <td><?php 
	$qty = $lineData[15];
	$unitPrice = trim(str_replace(array("AU","$"),"",$lineData[16]));
	$postCost = trim(str_replace(array("AU","$"),"",$lineData[17])); 
	echo $totalPrice =  trim(str_replace(array("AU","$"),"",$lineData[20]));
	if($unitPrice*$qty+$postCost != $totalPrice){echo "<br /><b >NOT MATCH</b>";}
	
	//echo $lineData[16]
	
	
	
	
	?></td>
    <td>
      <p><?php echo "[".$lineData[1]."]".$lineData[2]."<br />".$lineData[5].$lineData[6]."<br />".$lineData[7].$lineData[8].$lineData[9];   
	if($numberExist==0){ echo "<b style=\" text-decoration:underline;\">NO NU</b>";}
	if($abnormal==1){echo "<b  style=\" text-decoration:underline;\">NO ST</b>";}
	?>
    <a href="http://www.fastway.com.au/pricing/quick-quote/quick-quote-result?PickupRF=MEL&Weight=1&Postcode=<?php echo $lineData[9]?>&Length=&Width=&Height=">Click Here</a></p>
    </td>
    <td valign="top"><?php echo $lineData[27]?><br /><?php echo $lineData[17]?></td>
    <td valign="top">&nbsp;</td>
    <td valign="top">&nbsp;</td>
  </tr>
<?php
	}
	$counter++;
}
?>
</table>

</body>
</html>